package StudyCode.summary.textfile;

import java.io.*;
import java.util.ArrayList;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GetLineListFromTextFile {
	public static void main(String[] argv) throws Exception {
		String filename = "E:/Copy/test1.txt";
		ArrayList<String> lineList = getLineList(filename);
		for (String s : lineList) {
			System.out.println(s);
		}
	}

	public static ArrayList<String> getLineList(String filename)
			throws IOException {

		if (filename == null)
			return null;

		File file = new File(filename);
		if (!file.exists()) {
			return null;
		}
		ArrayList<String> resultList = new ArrayList<String>();
		FileInputStream fis = new FileInputStream(file);
		InputStreamReader reader = new InputStreamReader(fis, "UTF-8");

		LineNumberReader lineReader = new LineNumberReader(reader);
		String line;

		while ((line = lineReader.readLine()) != null) {
			if (line.trim().equals(""))
				continue;
			resultList.add(line.trim());
		}
		lineReader.close();
		reader.close();
		fis.close();
		return resultList;
	}
}
